
<div class="bulk_update">

  <%= form_tag bulk_update_path %>

    <div class="distance_calculator">
      <h2>Distance Calculator</h2>
      <input id="lap" class="text" type="text" value="<%= @group.lap %>" /> Laps = 1 mile
      <br />
      <br>
      <h2>Date of most recent run</h2>
        <%= date_select :bulk, :date, :end_year => Time.now().year %>
    </div>
    <% if @runners.blank? %>
      <p class="error">There are no runners added yet.</p>
    <% else %>
      <table>
        <thead>
          <tr>
            <th>Runner</th>
            <th>Laps</th>
            <th>Sessions</th>
            <th class="last"></th>
          </tr>
        </thead>
        <tbody>
	<tr><td>Add to All</td>
	    <td><input id="master_lap" class="text" type="text" name="" value="" /></td>
            <td><input id="master_session" class="text" type="text" name="" value="" />
	</tr>
          <% @runners.each do |runner| %>
            <tr class="<%= cycle('odd', 'even') %>">
              <td><%= link_to h(runner.name), runner %></td>
              <td><input class="text lap" type="text" name="runner[runner<%= runner.id %>][lap]" value="" /></td>
              <td><input class="text session" type="text" name="runner[runner<%= runner.id %>][sessions]" value="" /></td>
              <td><input class="text" type="hidden" name="runner[runner<%= runner.id %>][date]" value="" /></td>
              <input class="text" type="hidden" name="runner[runner<%= runner.id %>][distance]" value="" />
              <input class="text" type="hidden" name="runner[runner<%= runner.id %>][runner_id]" value="<%=runner.id%>" />
            </tr>
          <% end %>
        </tbody>
      </table>

    <% end %>

    <p>
      <input id="entry_submit" name="commit" type="submit" value="Create" onClick="return convertGroupLapToMiles();" class="submit">
    </p>

  </form>

</div>
<script type="text/javascript">
	function update_all_lap() {
	    jQuery('.lap').each( function() { jQuery(this)[0].value = jQuery('#master_lap')[0].value })
	}
	function update_all_session() {
	    jQuery('.session').each( function() { jQuery(this)[0].value = jQuery('#master_session')[0].value })
	}
	jQuery('#master_lap').bind("change", update_all_lap)
	jQuery('#master_session').bind("change", update_all_session)


	function stopRKey(evt) {
  	    var evt = (evt) ? evt : ((event) ? event : null);
  	    var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  	    if ((evt.keyCode == 13) && (node.type=="text"))  {return false;}
	}

	document.onkeypress = stopRKey;

</script>